package com.smartao.core.info.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerDetector {
	
	private static final Logger logger = LoggerFactory.getLogger(ServerDetector.class);

	public static final String GERONIMO_CLASS = "/org/apache/geronimo/system/main/Daemon.class";
	public static final String JBOSS_CLASS = "/org/jboss/Main.class";
	public static final String JETTY_CLASS = "/org/mortbay/jetty/Server.class";
	public static final String JONAS_CLASS = "/org/objectweb/jonas/server/Server.class";
	public static final String OC4J_CLASS = "/oracle/jsp/oc4jutil/Oc4jUtil.class";
	public static final String ORION_CLASS = "/com/evermind/server/ApplicationServer.class";
	public static final String PRAMATI_CLASS = "/com/pramati/Server.class";
	public static final String RESIN_CLASS = "/com/caucho/server/resin/Resin.class";
	public static final String REXIP_CLASS = "/com/tcc/Main.class";
	public static final String SUN7_CLASS = "/com/iplanet/ias/tools/cli/IasAdminMain.class";
	public static final String SUN8_CLASS = "/com/sun/enterprise/cli/framework/CLIMain.class";
	public static final String TOMCAT_CLASS = "/org/apache/catalina/startup/Bootstrap.class";
	public static final String WEBLOGIC_CLASS = "/weblogic/Server.class";
	public static final String WEBSPHERE_CLASS = "/com/ibm/websphere/product/VersionInfo.class";
	
	/**
	 * 检测服务器类型，支持Tomcat，Jboss，Weblogic，Websphere 默认为Tomcat
	 * @return AppServer的子类
	 */
	public static AppServer detectServer(){
		Class<ServerDetector> clazz = ServerDetector.class;
		AppServer appServer=new Tomcat();
		if(clazz.getResource(JBOSS_CLASS)!=null){
			appServer = new Jboss();
		}
		if(clazz.getResource(WEBLOGIC_CLASS)!=null){
			appServer = new Weblogic();
		}
		if(clazz.getResource(WEBSPHERE_CLASS)!=null){
			appServer = new Websphere();
		}
		logger.info("Using Server:{}",appServer.getServerInfo());
		return appServer;
	}

}
